package com.zkw.algorithm.Onotation;

/**
 * Created by Administrator on 2016/5/25 0025.
 */
public class Test {
    /**
     * 求和的时间复杂度为O(n)
     * @param count
     */
    private static void printSumOri(int count){
        int sum=0;
        for (int i=0;i<count;i++){
            sum+=i;
        }
//        System.out.println(sum);
    }
    /**
     * 求和的时间复杂度为O(1)
     * @param count
     */
    private static void printSum(int count){
        int sum=0;
        sum=count*(count+1)/2;
//        System.out.println(sum);
    }

    private static void te(int n){
        for (int count=1;count<n;count++){
            printSumOri(count);
        }
    }

    private static void te1(int n){
        for (int count=1;count<n;count++){
            printSum(count);
        }
    }



    public static void main(String[] args) {
        int n=100000;
        long start=System.currentTimeMillis();
       te(n);
        System.out.println("te cost time(ms): "+String.valueOf(System.currentTimeMillis()-start));
        long start1=System.currentTimeMillis();
       te1(n);
        System.out.println("te1 cost time(ms): "+String.valueOf(System.currentTimeMillis()-start1));
    }
}
